// Author: wsfuyibing <682805@qq.com>
// Date: 2025-07-02

package operations

import (
	"gitee.com/go-libs/db-xorm/db"
	"server/app/kind"
)

// Prepay
// 试算结果.
type Prepay struct {
	TotalAmount   kind.Balance
	TotalDiscount kind.Balance

	// BalanceAmount
	// 余额承担.
	BalanceAmount kind.Balance

	// CouponAmount
	// 优惠券承担.
	CouponAmount kind.Balance

	// MemberAmount
	// 会员承担.
	//
	// 会员特权低价购票/购物时抵扣金额.
	MemberAmount kind.Balance

	// MemberAvailable
	// 会员截止日期.
	MemberAvailable db.Date

	// MemberCanAmount
	// 会员可承担.
	//
	// 非会员若成为会员, 其特权可承担的部分.
	MemberCanAmount kind.Balance

	// PayAmount
	// 自付金额.
	PayAmount kind.Balance

	// UserBalance
	// 用户余额.
	UserBalance kind.Balance
}

func NewPrepay() *Prepay {
	return &Prepay{}
}

func (o *Prepay) End(entity *Entity) {
	if entity.ArcadeMember != nil && entity.ArcadeMember.Available() {
		o.MemberAvailable = entity.ArcadeMember.AvailableEnd
	}

	if entity.UserStatistic != nil {
		o.UserBalance = entity.UserStatistic.Balance
	}
}

func (o *Prepay) ResetPayAmount() *Prepay {
	o.BalanceAmount = o.BalanceAmount.Reset()
	o.CouponAmount = o.CouponAmount.Reset()
	o.MemberAmount = o.MemberAmount.Reset()
	o.MemberCanAmount = o.MemberCanAmount.Reset()
	o.TotalDiscount = (o.MemberAmount + o.BalanceAmount + o.CouponAmount).Reset()
	o.PayAmount = (o.TotalAmount - o.TotalDiscount).Reset()
	return o
}
